package com.zz.yt.test.delegate.net;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.whf.android.jar.base.latte.BaseActivity;
import com.whf.android.jar.dao.TokenDao;
import com.whf.android.jar.net.utils.RestClientUtils;
import com.zz.yt.test.R;
import com.zz.yt.test.delegate.net.up.UpVersionUtils;

import java.util.WeakHashMap;


/**
 * @author qf
 * @version 2023-04-23
 */
public class ANetActivity extends BaseActivity implements AdapterView.OnItemClickListener {


    private final String[] title = {
            "切换服务 ",
            "新旧 RetrofitT 请求",
            "带参数的文件上传",
            "app下载",
    };

    private final Class[] classes = {
            ServerActivity.class,
            MapActivity.class,
            MapActivity.class,
    };

    ListView idListView;

    @Override
    protected Object setLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState) {
        addMarginTopEqualStatusBarHeight(findViewById(R.id.id_title));
        setTextView(R.id.id_title, "网络请求模块");
        idListView = findViewById(R.id.id_list_view);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                ANetActivity.this,
                android.R.layout.simple_list_item_1,
                title);
        idListView.setAdapter(adapter);
        idListView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (position == 2) {
            String url = "http://10.150.1.24:29200/vcleRefuelRecord/refuelScanConfirm";
            TokenDao.setAuthorization("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjdXJyZW50VGltZU1pbGxpcyI6IjE4MyIsImV4cCI6MTcxMjQ5MjM2MSwiYWNjb3VudCI6IjE4M19hcHAifQ.Qaesq-g_HuhmBVDepI1SVTpPs2XgvO5GFqdckD08BhA");
            //带参数上传。
            WeakHashMap<String, Object> params = new WeakHashMap<>();
            params.put("refuelTime", TimeUtils.getNowString());
            params.put("plateNumber", "桂A500NH");
            params.put("oilCard", "1000114500013852104");
            params.put("oilType", "92号汽油");
            params.put("vcleType", "车厢可卸式垃圾车-3吨");
            params.put("orgName", "贺州项目");
            params.put("volume", "27.2");
            params.put("money", "200");
            params.put("thisMile", "243100");
            //带文件的上传。
            WeakHashMap<String, String> hashMap = new WeakHashMap<>();
            hashMap.put("oilerSign", "/storage/emulated/0/Android/data/com.crcm.android.collet.sanitation/cache/signature/signature.png");
            RestClientUtils.create().inPost(url, params, hashMap, response -> {
                hideLoading();

            });
            RestClientUtils.create().inPart(url, params, response -> {
                hideLoading();

            });
            return;
        }
        if (position == 3) {
            UpVersionUtils.create(this)
                    .show();
            return;
        }
        Class c = classes[position];
        ActivityUtils.startActivity(c);
    }


}

